<template>
  <div v-if="!isLoading">
      <eagle-sing-diy v-if="zIndex==8" ref="setzIndex" :isContinue="true" :mzIndex="zIndex" :id="id" v-on:FilePathClick="FilePathClick"></eagle-sing-diy>
      <div style="text-align: center; margin: 10px">{{ form.CheckTaskName }}</div>
      <div class="block-box">
        <div class="block-box_item">
          <eagle-cell-group :border="border">
            <eagle-input 
              label="检查类型"
              :value="form.CheckTypeName +(form.CheckType == 'ZCLX0002' ? '(' + form.ItemTypeName + ')' : '')"
              readonly
            />
            <eagle-input
            label="检查企业"
            autosize
            type="textarea"
            rows="1"
            v-if="form.CType=='2'"
            :value="form.EnterpriseName"
            readonly
            islink
            @click="goCompanyDetail(form.EnterpriseCode)"
            />
            <eagle-input
              label="来源计划"
              autosize
              type="textarea"
              rows="1"
              v-if="form.CheckPlanName"
              :value="form.CheckPlanName"
              readonly
              islink
              @click="goFromDetail()"
            ></eagle-input>
            <eagle-input
              label="任务发起人"
              :value="form.CreateChnName"
              readonly
            ></eagle-input>
            <eagle-input
              label="任务发起时间"
              :value="form.CreateDate"
              readonly
            ></eagle-input>
            <eagle-input
              label="检查人"
              :value="form.CheckNames"
              autosize
              type="textarea"
              rows="1"
              readonly
              islink
              @click="handleUserManager"
            ></eagle-input>
            <eagle-input
              label="检查时间段"
              :value="form.StartDate + '至' + form.EndDate"
              autosize
              type="textarea"
              rows="1"
              readonly
            ></eagle-input>
            <eagle-input
              label="检查要求"
              :value="form.CheckRequirement || '暂无检查要求'"
              autosize
              type="textarea"
              rows="1"
              readonly
            />
            <eagle-input
              label="任务状态"
              :value="form.StatusName || '无任务状态'"
              autosize
              type="textarea"
              rows="1"
              readonly
              
            />
            <eagle-input
              :label="CheckRecordName"
              :value="CheckRecordNameValue"
              readonly
              islink
              @click="goMyTaskHistoryList()"
            />
            <eagle-input
              v-if="form.Status>10"
              label="检查报告"
              :value="'当前已生成'+form.ReportCnt+'份报告'"
              readonly
              islink
              @click="goReportHistoryList(form.CTCode)"
            />
            <eagle-input
              label="检查现场照片"
              :value="'已上传' + form.PhotoCnt + '张现场照片'"
              readonly
              islink
              @click="goMyTaskFileList()"
            />
            <eagle-input
            v-if="this.form.Status == 100 || this.form.Status == 30"
              label="验收现场照片"
              :value="'已上传' + form.ReturnPhotoCnt + '张现场照片'"
              readonly
              islink
              @click="goMyTaskFileList(2)"
            />
            <eagle-input 
            v-if="form.SignAttachs"
            label="签名"
            >
            <template #input>
              <eagle-image-preview :images="form.SignAttachs"></eagle-image-preview>
            </template>
         
          </eagle-input>
          </eagle-cell-group>
        </div>
      </div>
      <div class="block-box" v-if="form.Templates.length > 0">
        <div class="block-box_item">
          <div class="block-box_title">已分配的检查表</div>
          <div class="operate_list">
            <eagle-row
              v-for="(item, index) in form.Templates"
              :key="index"
              class="operate_row"
              @click="goCheckResult(item)"
            >
              <eagle-col span="1">{{ index + 1 }}</eagle-col>
              <eagle-col offset="1" span="17">{{ item.TName }}</eagle-col>
              <eagle-col offset="1" span="4">
                <eagle-tag v-if="item.Status < 10" size="mini" type="primary">未完成</eagle-tag>
                <eagle-tag v-if="item.Status == 10" size="mini" type="warning">已完成</eagle-tag>
              </eagle-col>
            </eagle-row>
          </div>
        </div>
      </div>
      <div class="btns m-10" v-if="this.form.Status == 10 && !isDate">
        <eagle-button style="flex:1;" type="green2" @click="goTakePhoto()">随手拍</eagle-button>
        <eagle-button style="flex:1;" class="ml-10" @click="goCheckList()">检查表检查</eagle-button>
        <eagle-button style="flex:1;" class="ml-10" type="orange" @click="goCheckBasis()">依据检查</eagle-button>
      </div>
      <div
        class="btns ml-10 mr-10 mb-10"
        v-if="this.form.Status == 10 && !isDate"
      >
        <eagle-button style="flex:1;" type="green" @click="handleClose()"> 结束任务 </eagle-button>
        <eagle-button v-if="isJG" class="ml-10" style="flex:1;" type="green" @click="handdelete()"> 删除任务 </eagle-button>
      </div>

      <div class="btns m-10" v-if="this.form.Status == 100 && !isDate&&isJG">
        <eagle-button style="flex:1;" class="mls" type="green" @click="Generatereport(0)"> 生成报告 </eagle-button>
        <eagle-button  style="flex:1;background-color: #f25536;" class="mls ml-10" @click="withdraw()">撤回任务</eagle-button>
      </div>

      <div class="btns m-10" v-if="this.form.Status == 30 && !isDate&&isJG">
        <eagle-button style="flex:1;" class="mls" type="green" @click="Generatereport(0)"> 生成报告 </eagle-button>
        <eagle-button style="flex:1;background-color: #f25536;" class="mls" @click="withdraw()">撤回任务</eagle-button>
        <eagle-button style="flex:1;background-color: #e18c0b" class="mls" type="orange" @click="Nomoreacceptance(item)">不再验收</eagle-button>
      </div>
      <div class="btns m-10" v-if="this.form.Status == 20 && !isDate && isJG">
        <eagle-button style="flex:1;" class="mls" type="green" @click="Generatereport(1)"> 生成报告 </eagle-button>
        <eagle-button style="flex:1;" class="mls ml-10" @click="handleAdd">提交任务</eagle-button>

      </div>
  
  </div>
</template>

<script>
import { getDateTime } from "@/utils/getDate";
import { Dialog } from "vant";
import { mapGetters } from "vuex";
import { ref } from "vue";
import  HttpContent from "@/lib/HttpContent";

// import { deepClone } from "@/utils";
import EagleSingDiy from './eagle-sing-diy.vue';
export default {
  components: { EagleSingDiy, EagleSingDiy },
  data() {
    return {
      baseUrl: process.env.VUE_APP_BASE_API,
      id: this.$route.query.id,
      isDate: true,
      border: false,
      zIndex: -8,
      adds:'',
      imgUrl: "",
      form: {
        Templates: [],
      },
      CheckRecordName: " 检查记录",
      url:this.HttpContent.DangerCheckTask_Detail,
      isJG:false,
      CheckRecordNameValue:'',
      CTCode:'',
      isLoading:true
    };
  },
  computed: {
    ...mapGetters(["CompanyCode"]),
  },
  created() {
    this.isDate = this.$route.query.isDate=='true';
    if(this.$store.state.CompanyType == "JG"){
      this.url=this.HttpContent.DangerCheckTask_Detail_JG
      this.isJG=true
      this.$store.state.title="监查任务详情"
    }
  
    this.geDetail();
  },
  methods: {
    handleUserManager(){
      this.$router.push('/danger/UserListManager?ctCode='+this.ctCode)
    },
       // 删除任务
       handdelete(){
      let that = this;
      Dialog.confirm({
        title: "询问",
        message: "您确定要删除当前检查任务吗?",
      })
        .then(() => {
          that.$axios
          .get("/DangerCheckTaskJG/DeleteTask",{params:{ id: this.id }})
          .then((res)=>{
            that.$toast.success("删除成功！");
            that.$router.goRefresh(-1);
          })
        })
        .catch(() => {
          // on cancel
        });

    },
   // 签字
   FilePathClick(FilePath) {
      this.imgUrl = FilePath;
      this.handleClose_2()
    },

    // 签名
    handleClose(add){
      this.adds = add;
      this.zIndex = 8;
      this.isCertificate = true;
      this.isCertificate2 = true;
      this.$refs.setzIndex.setzIndex(this.zIndex);
      // this.overwrite();
    },

    handleAdd(){
      Dialog.confirm({
        thile:'询问',
        message:'是否提交任务',
      }).then(()=>{
          this.$axios.get('/DangerCheckTaskJG/SubmitDanger',{params:{id:this.id}}).then(res=>{
          this.$toast.success('提交成功')
          this.geDetail()
          })


      }).catch(()=>{})

    },
    goReportHistoryList(ctCode){
      this.$router.push({
        path: "/Danger/HistoryReport",
        query: {
          ctCode,
        },
      });
    },
    goCompanyDetail(value){
      this.$router.push({
        path: "/BaseInfo",
        query: {
          CompanyCode: value,
        },
      });

    },
    goMyTaskFileList() {
      this.$router.push(
        "/Danger/DangerCheckTaskFileList?ctCode=" + this.form.CTCode
      );
    },

    goMyTaskHistoryList() {
      let url="/Danger/DangerCheckTaskDetailList"
      if(this.isJG){
        url="/Danger/RecordList"

      }
      this.$router.push({
        path: url,
        query: {
          ctCode: this.form.CTCode,
          status:this.form.Status,
          dataType:'TaskDetail'
          
        },
      });
    },

    goCheckBasis() {
      this.$router.push({
        path: "/Danger/Classifys?hasPhoto=hasPhoto",
        query: { ctCode: this.form.CTCode, OriginType: 2 },
      });
    },
    // 随手拍
    goTakePhoto() {
      let url = '/Danger/DangerCheckTaskDetailEdit'
      if(this.isJG){
          url='/Danger/DangerCheckTaskDetailEdit_JG'
      }
      this.$router.push({
        path: url,
        query: { ctCode: this.form.CTCode, originType: 3 },
      });
    },

    goCheckList() {
      this.$router.push(
        "/Danger/DangerCheckTaskTemplateList?ctCode=" + this.form.CTCode
      );
    },

    // 获取详情
    geDetail() {
      let that = this;
      that.$axios
      // .get("/DangerCheckTask/GetDetail",{params:{ id: that.id }})
      .get(this.url,{params:{ id: that.id }})
      .then((res) => {
        that.form = res.data;
        that.form.StartDate = getDateTime(this.form.StartDate);
        that.form.EndDate = getDateTime(this.form.EndDate);
        that.form.CreateDate = getDateTime(this.form.CreateDate);
        let status=that.form.Status
        that.ctCode=that.form.CTCode
        if(status <20 ||status==100||status==25){
          that.CheckRecordName = "检查记录";
          that.CheckRecordNameValue='隐患：' + that.form.HiddenDangerCnt + ' /检查：' + that.form.CheckCnt
        }
        else if (status == 20) {
          that.CheckRecordName = "待提交隐患记录";
          that.CheckRecordNameValue="隐患："+that.form.HiddenDangerCnt
        }else if (status == 30) {
          that.CheckRecordName = "待验收隐患记录";
          that.CheckRecordNameValue="隐患："+that.form.HiddenDangerCnt
        }
        this.isLoading=false

      });
    },
    goFromDetail(item) {
      //  this.$toast("暂无来源计划AA"+"=="+this.form.CpID);
      if (this.form.CpID) {
        this.$router.push("/Danger/DangerCheckPlanView?cpId=" + this.form.CpID);
      } else {
        this.$toast("暂无来源计划");
      }
    },

    goCheckResult(item) {
      let url = this.isJG?"/Danger/DangerTemplateDetailJG":"/Danger/DangerTemplateDetail"
      if (item.Status < 10) {
        this.$router.push({
          path: url,
          query: {
            tCode: item.TCode,
            tRand: item.TRand,
            CompanyCode: this.CompanyCode,
            ctCode: this.form.CTCode,
          },
        });
      } else {
        this.$router.push(
          "/Danger/DangerTemplateCheckResult?tCode=" +
            item.TCode +
            "&tRand=" +
            item.TRand
        );
      }
    },
    handleClose_2() {
      let url = this.isJG?"/DangerCheckTaskJG/End": "/DangerCheckTask/End"
      
      let that = this;
      Dialog.confirm({
        title: "询问",
        message: "您确定要结束当前检查任务吗?",
      })
        .then(() => {
          that.$axios
          .post(url,{ id: that.id,SignAttach:this.imgUrl })
          .then((res)=>{
            that.$toast.success("结束成功！");
            that.geDetail()
          
          })
        })
        .catch(() => {
          // on cancel
        });
    },
        // 生成报告
        Generatereport(flag) {
          this.title = "生成整改报告(按任务)";
          this.$router.push({
            path: '/Danger/Reportdetail?codes='+ this.form.CTCode,
            // path: "/OtherDanger/CorrectiveReport",
            query: { type: "Task", reportType: flag,isRead:false},
          });

      // this.$router.push({
      //     name: "Reportdetail",
      //     query: {
      //       codes: this.form.CTCode,
      //       ReportType:flag,
      //       type: 'Task',
      //       reportType: this.reportType,
      //       Name:reportName,
      //       IDS:ids.join(',')
      //     },
      //   });
    },
    withdraw() {
      let that = this;
      Dialog.confirm({
        title: "询问",
        message: "您确定要撤回此项任务吗?",
      })
        .then(() => {
          that.$axios
          .get("/DangerCheckTaskJG/BackDanger",{params:{ id: this.id }})
          .then((res)=>{
            that.$toast.success("撤回成功！");
            that.$router.goRefresh(-1);
          })
        })
        .catch(() => {
          // on cancel
        });


    },
        // 不再验收
        Nomoreacceptance() {
      let that = this;
      Dialog.confirm({
        title: "询问",
        message: "您确定要不再验收此项任务吗?",
      })
        .then(() => {
          that.$axios
          .get("/DangerCheckTaskJG/GiveupVerify",{params:{ id: this.id }})
          .then((res)=>{
            that.$toast.success("提交成功！");
            that.$router.goRefresh(-1);
          })
        })
        .catch(() => {
          // on cancel
        });

    }
  },
};
</script>

<style lang="less" scoped>
/*
        .main {
            height: 100vh;
        }
    */
.bottom-btns {
  margin-top: 10px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .submit-btn {
    width: 32%;
    height: 35px;
    font-size: 14px;
  }
  .delete-btn {
    width: 100%;
    height: 35px;
    font-size: 14px;
  }
}
.det_top_box {
  padding: 10px;
  background-color: #e8f1f8;
}

.detail_header {
  color: #ffffff;
  background: url("../../../assets/Images/AppIcon/image_riskunit_detail_bg.png");
  background-size: cover;
  padding: 10px;
  border-radius: 5px;
  /*background-color: #fff;*/

  .det_top {
    display: flex;
    justify-content: space-between;

    .dep_top_img {
      height: 20px;
      width: 20px;
      margin-right: 5px;
    }
  }

  .det_name {
    margin-top: 20px;
    text-align: center;
  }

  .det_location {
    text-align: center;
    margin-bottom: 20px;
  }
}

.det_tab {
  padding: 10px;
  .det_tab_item {
    padding: 10px 0;
    background-color: #fff;
    border-radius: 5px;
    margin-bottom: 10px;

    .det_tab_item_text {
      padding: 0 10px;
    }
  }
}
.text_box {
  padding: 10px;
  border-radius: 5px;
  /*background-color: #e8f1f8;*/
  margin-bottom: 10px;

  .text_top {
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    .top_link {
      color: #1989fa;
    }
  }

  .text_item {
    display: flex;
    justify-content: space-between;
    margin-left: 10px;

    .item_link {
      color: #1989fa;
    }
  }

  .text_img {
    display: flex;
    align-items: center;

    .img_item {
      width: 33.3%;
      text-align: center;

      img {
        height: 25px;
        width: 25px;
        margin-bottom: 10px;
      }
    }
  }

  .text_history {
    display: flex;
    vertical-align: middle;
    margin-bottom: 10px;
  }

  .text_member {
    color: #1989fa;
    margin-bottom: 10px;
  }

  .text_total_img {
    display: flex;
    align-items: center;

    .img_item {
      width: 33.3%;
      text-align: center;

      .img_item_top {
        display: flex;
        vertical-align: middle;
        margin-bottom: 10px;
      }
      img {
        height: 15px;
        width: 15px;
        margin-right: 5px;
      }
    }
  }
  .text_record_list {
    .list_row {
      display: flex;
      justify-content: space-between;
      margin-bottom: 10px;
      > div {
        width: 33.3%;
      }
      .row_center {
        text-align: center;
      }
      .row_right {
        text-align: right;
      }
    }
  }
}
.operate_list {
  font-size: 12px;
  border: 1px solid #e8f1f8;
  .operate_row_first {
    padding: 10px;
    background-color: #e8f1f8;
    border-bottom: 1px solid #e8f1f8;
    margin-bottom: 10px;
  }
  .operate_row {
    padding: 10px;
    border-bottom: 1px solid #e8f1f8;
    /*margin-bottom: 10px;*/
  }

}
</style>
